package com.example.controller;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.example.annotation.PassToken;
import com.example.entity.Department;
import com.example.entity.department.DepartmentOneBO;
import com.example.entity.department.DepartmentTreeBO;
import com.example.entity.persion.Persion;
import com.example.service.IDepartmentService;
import com.example.service.ITimeAreaService;
import com.example.utils.ProxyUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;
import java.util.logging.Logger;

/**
 * @author ChenXiaoBin
 * on 2019-07-04
 */
@RestController
@RequestMapping("/V1.0")
public class DepartmentController {

    private Logger LOG = Logger.getLogger(String.valueOf(this.getClass()));
    @Autowired
    private IDepartmentService departmentService;

    @Autowired
    private ITimeAreaService timeAreaService;

    @ApiOperation(value = "创建IP代理")
    @GetMapping("/ip/proxy")
    public void ipProxy() throws IOException {
        Persion persion = new Persion();
        persion.setName("你的名字你的名字你的名字");
        persion.setId("wode123");
        ProxyUtils.validateHttp("58.51.95.85", 50223, JSONUtil.toJsonStr(persion));
    }


    @ApiOperation(value = "递归查询部门列表")
    @GetMapping("/get/department/list")
    @PassToken
    public List<DepartmentTreeBO> getDepartment() {
        Department department = new Department();
        department.setDepartmentName("一级部门");
        departmentService.selectList(new EntityWrapper<>(department).ne("id", 1));
        return departmentService.getDepartmentList(0);
    }


    @ApiOperation(value = "查询近七天曲线图12")
    @GetMapping("/cure")
    @PassToken(required = true)
    public void curve() {
        timeAreaService.curve();
    }

    @ApiOperation(value = "测试rerdis做缓存")
    @PutMapping("/redis/cacheer")
    @PassToken
    public void departmentList() {
//         departmentService.departmentList();
//        departmentService.getDepartmentByDate("2019-11");
        DepartmentOneBO departmentOneBO = departmentService.getCreateTime();
    }

}
